#include <iostream>
#include <cmath>

using namespace std;

void Invert(char* input, int num_element)
{
	for (int i = 0; i < num_element / 2; ++i)
	{
		char tmp = input[i];
		input[i] = input[num_element - 1 - i];
		input[num_element - 1 - i] = tmp;
	}
}

void copyString1(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	while (length > 0 && input[offset] != '\0' && output[output_offset] != '\0')
	{
		if (!invert)
			output[output_offset++] = input[offset++];
		else output[output_offset++] = input[max(offset + length, (int)strlen(input))];
		length--;
	}
	output[output_offset] = '\0';
}


void copyString2(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	memcpy(output + output_offset, input + offset, length + 1);
}

void copyString3(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	char tmp = input[offset + length];
	char tmp2 = output[output_offset + length];
	input[offset + length] = '\0';
	strcpy(output + output_offset, input + offset);
	if (invert)
		Invert(output, strlen(output));
	input[offset + length] = tmp;
	output[output_offset + length ] = tmp2;
}
void main()
{
	//char s1[] = "hello my name is hoang";
	//char s2[] = "this is my 3rd day of internship";
	////copyString2(s1,1,4,true,s2, 5);
	//copyString3(s1,1,4,false,s2, 5);
	//cout << s2;
char st[] = "Hello World";
char st2[] = "My name is C++";
copyString1(st, 6, 5, true, st2, 11) ;
cout << st2;

}